package cn.ac.cintcm.dao.hibernate.oracle;

import java.util.List;

import cn.ac.cintcm.dao.hibernate.UserDaoGeneric;
import cn.ac.cintcm.model.User;

/**
 * This class interacts with Spring's HibernateTemplate to save/delete and
 * retrieve User objects.
*/
public class UserDaoHibernate extends UserDaoGeneric {

    /** 
     * {@inheritDoc}
    */
    @SuppressWarnings("unchecked")
	public List<User> getAttentionUser(Long userId) {
    	String hsql = "select p from User u, User p, Therapy t where " +
    			"t.notify=0 and extract(day from (current_date - t.tdate))>=(t.dosage + 2) " +
    			" and p.id=t.patient and u.id=" + userId + " and p member of u.patients";
	    return  getHibernateTemplate().find(hsql);
	}

    /** 
     * {@inheritDoc}
    */
	@SuppressWarnings("unchecked")
	public List<User> getRecentUser(Long userId) {
    	String hsql = "select distinct p from User u, User p, Therapy t where " +
    			"extract(day from (current_date - t.tdate))<=7 and p.id=t.patient " +
    			"and u.id=" + userId+ " and p member of u.patients";
	    return  getHibernateTemplate().find(hsql);
	}

    
}
